

import java.util.ArrayList;

import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

import it.randomtower.engine.entity.Entity;


/**
 * 
 * @author micole
 * Creates a player on the screen that you can select to move
 */
public class PlayerSelect extends Entity {

	
	private Animation player;
	private int playerX = 0;
	private int playerY = 0;
	
	public PlayerSelect(int x, int y) {
		super(x, y);
		playerX = x;
		playerY = y;
		// TODO Auto-generated constructor stub
	}
	
	public void init(GameContainer container){
		try {
			SpriteSheet sheet = new SpriteSheet("images/karbonator.png", 32, 32);
			player = new Animation();
			player.setAutoUpdate(true);
			for (int frame = 0; frame < 3; frame++) {
				player.addFrame(sheet.getSprite(frame, 0), 150);
			}
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void update(GameContainer container, int delta) {
		
	}
	
	public void render(GameContainer container, Graphics g)
			throws SlickException {
		g.drawAnimation(player, playerX, playerY);
	}
	
	public boolean isPlayerAtLocation(int x, int y){
		return(playerY == y && playerX == x);
	}
	
	public void movePlayer(GameContainer container, ArrayList<PlayerSelect> players){
		Input input = container.getInput();
		int mouseX = input.getMouseX();
		int mouseY = input.getMouseY();
		for(PlayerSelect player:players){
			if(player.isPlayerAtLocation(mouseX, mouseY))
				break;
			else{
				playerX = mouseX;
				playerY = mouseY;
			}
		}
	}
	
	
}